package com.api.action.v1;

import com.api.service.v1.ApkAPIService;
import com.bean.ResponseBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/api/v1")
public class ApkAPIAction {

	@Autowired
	private ApkAPIService apkapiservice;

	/**
	 * 查出所有apk
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("/getapk")
	@CrossOrigin("*")
	public ResponseBean findapkall() throws IOException {
		
		return  apkapiservice.findapk();
	}

	/**
	 * APK+1
	 * @param packageName
	 * @param mac
	 * @return
	 */
	@RequestMapping("/apkClickCount")
	public ResponseBean apkClickCount(@RequestParam(defaultValue= "")String packageName, @RequestParam(defaultValue="")String mac){
		ResponseBean bean = new ResponseBean(200, "success", null);
		if("".equals(packageName))
		{
			return bean;
		}
		int n = apkapiservice.tongji_add(packageName);
		if(n>0)
		{
			bean.setData("成功增加访问次数");
		}
		return bean;
	}
}
